﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
namespace HealthSystem
{
    public partial class ChooseSchool : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        private void BindGrid()
        {
            int count = 0;
            string district = null;
            district = Request["districtid"] as string;
            HW_SchoolManager manager = new HW_SchoolManager();
            Gird1.DataSource=manager.GetByDistrict(Gird1.PageIndex,Gird1.PageSize,out count,district,null);
            Gird1.RecordCount = count;
            Gird1.DataBind();
        }
        protected void Double_Click(object sender, ExtAspNet.GridRowClickEventArgs e)
        {
            string schoolcode = Gird1.Rows[e.RowIndex].DataKeys[0] as string;
            string schoolname = Gird1.Rows[e.RowIndex].DataKeys[1] as string;
            PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(schoolcode, schoolname) + ActiveWindow.GetHidePostBackReference());
        }
        protected void PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Gird1.PageIndex = e.NewPageIndex;
            if (actionbt.Text == "search")
            {
                Search(searchbox.Text);
            }
            else
            {
                BindGrid();
            }
        }
        protected void Search_Clik(object sender, EventArgs e)
        {
            Gird1.PageIndex = 0;
            Search(searchbox.Text.Trim());
        }
        private void Search(string searchString)
        {
            if (string.IsNullOrEmpty(searchString))
            {
                BindGrid();
                actionbt.Text = "";
            }
            else
            {
                int count = 0;
                string district = null;
                district = Request["districtid"] as string;
                HW_SchoolManager manager = new HW_SchoolManager();
                Gird1.DataSource = manager.GetByDistrict(Gird1.PageIndex, Gird1.PageSize, out count, district, searchString);
                Gird1.RecordCount = count;
                Gird1.DataBind();
                actionbt.Text = "search";
            }
        }
    }
}